
#include "stm8l15x.h"
 #include "pubset.h"
 #include "extern1.h"
#include "froze_perr.h"


 


extern strRamData RamData;

extern  u8* @tiny tpChar;
extern  u8* @tiny tpBase;
 /*
  struct STPERRUNIT stperrstartunit;
  struct STPERRUNIT stperrendeunit;
*/

void
format_stperr (struct STPERRUNIT *p)
{
  p->lTime = RamData.RTCTime;
  p->lAct_Use = RamData.LVSave[0].FLUse.SectUse.Use;
  p->lAct_RevUse = RamData.LVSave[0].FLUse.RevSectUse.Use;
}


void froze_peffstart (void)
{
  struct STPERR s;
	
	if  ( *((u32 *)&sMainBuf)) 
			Up_FrozeData((uc8 *) &sMainBuf, _FROZE_PERR_);
	else
			 iinc_int( (u16 *)&(FlashInfo.FrozeCnt[_FROZE_PERR_START_ & 0x3f ]  ));
 
  FillRam ((u8 *) & s, 0, sizeof (struct STPERR));
  format_stperr(&(s.stperrstartunit));
  WriteSTM8Flash((u8 *)&sMainBuf , (u8 *) & s,
		  sizeof (struct STPERR));
	
}

void froze_peffend(void)
{
  struct STPERR s;
	if ((!_lstperr_null ) &&  (  _lstperr_endnull ))
	{
			CopyRam ((u8 *) & s, (u8 *) & sMainBuf , sizeof (struct STPERR));
			format_stperr(&(s.stperrendeunit));
			WriteSTM8Flash  ((u8 *) &sMainBuf , (u8 *) & s, sizeof (struct STPERR));
	}
}




void
froze_funread (struct STPERR *s, struct  STFROZE_COMM_PERR *d)
{
  FillRam ((u8 *) d, 0, sizeof (struct STFROZE_COMM_PERR));
  if (s)
    {
      GetCntTime (d->csEndTime, s->stperrendeunit.lTime,(S_SEC|T_SEC));
      GetCntTime (d->csStartTime, s->stperrstartunit.lTime,(S_SEC|T_SEC));
      d->lPrevAct_Use = s->stperrstartunit.lAct_Use;
      d->lPrevActRevUse = s->stperrstartunit.lAct_RevUse;

    }


}

u32
RxPwrErrRcd(strDispCode const *pCode, u8 FType)
{
 
  u8 cOffset =   (pCode ->Code)&0xFF;  
 
   struct STPERR *sopen; 
 
  sopen =  (cOffset-1) ? (struct STPERR *) GetFrozeStart (FType  ,  cOffset -1 ) : & sMainBuf ;

   froze_funread (sopen, (struct STFROZE_COMM_PERR *) (tpChar ));

  tpChar  += sizeof (struct STFROZE_COMM_PERR);
 

}
